import { reactive } from 'vue'
import { defineStore } from 'pinia'

const useUserStore = defineStore('user', () => {
  const user = reactive({
    token: '',
    isSuper: false,
    name: '',
    id: 0,
    avatar: '',
    roles: [],
    permissions: []
  })

  function setUserInfo(userInfo) {
    for (const key in user) {
      user[key] = userInfo[key]
    }
  }

  function resetUserStore() {
    setUserInfo({
      token: '',
      isSuper: false,
      name: '',
      id: '',
      avatar: '',
      roles: [],
      permissions: []
    })
  }
  return { user, setUserInfo, resetUserStore }
})

export default useUserStore